/*
 * Ext JS Library 1.0.1
 * Copyright(c) 2006-2007, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://www.extjs.com/license
 */
var Example = {
    init : function(){
        // example of custom renderer function
        function italic(value){
            return '<i>' + value + '</i>';
        }

		// example of custom renderer function
        function change(val){
            if(val > 0){
                return '<span style="color:green;">' + val + '</span>';
            }else if(val < 0){
                return '<span style="color:red;">' + val + '</span>';
            }
            return val;
        }
		// example of custom renderer function
        function pctChange(val){
		    if(val > 0){
		        return '<span style="color:green;">' + val + '%</span>';
		    }else if(val < 0){
		        return '<span style="color:red;">' + val + '%</span>';
		    }
		    return val;
		}
		
		var ds = new Ext.data.Store({
		    proxy: new Ext.data.HttpProxy({
		        url: 'http://www.creativeprooffice.com/apps/desktop/getAppDataJSON.php?getData=1&uID=1'
		    }),
		
		    reader: new Ext.data.JsonReader({
		        root: 'Projects',
		        id: 'ID'
		    }, [
		    {name: 'ID', mapping: 'ID'},
		    {name: 'Title', mapping: 'Title'}
		    ])
		
		});

        ds.load();

		var colModel = new Ext.grid.ColumnModel([
			{header: "ID", width: 50, sortable: true, dataIndex: 'ID'},
			{header: "Project Title", align: 'left', width: 450, sortable: true, dataIndex: 'Title'}
		]);

        // create the Grid
        var grid = new Ext.grid.Grid('grid-example', {
            ds: ds,
            cm: colModel
        });
        
        var layout = Ext.BorderLayout.create({
            center: {
                margins:{left:3,top:3,right:3,bottom:3},
                panels: [new Ext.GridPanel(grid)]
            }
        }, 'grid-panel');

        grid.render();
        

        grid.getSelectionModel().selectFirstRow();
		
    }	
};
Ext.onReady(Example.init, Example);